var allInfos = "";// 用来接收从服务器返回的所有信息
var className = new Array();// 班级名称
var classId = "";// 班级id
var stuClass = "";
var userNameSelect = ""; // 用户名选择控件

function getAllStudentInfos() {

	$.post("/ICSS/jobInfo?action=getAllStudentInfos", function(data) {
				allInfos = data;
				init();
			}, "json");
}

function init() {

	$.each(allInfos, function(i, stuInfo) {
				if (0 == i)
					addStuNameByClass(stuInfo.stuClassId);

				for (var j =0; j < className.length; j++) {
					if (stuInfo.className == className[j])
					return;
				}
					
				var option = new Option(stuInfo.className);
				option.value = stuInfo.stuClassId;
				stuClass.options.add(option);
				className.push(stuInfo.className);
			});
}

$(function() {
			stuClass = document.getElementById("stuClassId");
			userNameSelect = document.getElementById("uid");
			getAllStudentInfos();

			var classSelect = $("#stuClassId");

			classSelect.change(function() {
						addStuNameByClass(stuClass.value);

					});
		});

function addStuNameByClass(classID) {

	userNameSelect.options.length = 0;
	$.each(allInfos, function(i, stuInfo) {
				if (stuInfo.stuClassId == classID) {
					var option = new Option(stuInfo.userName);
					option.value = stuInfo.uid;
					userNameSelect.options.add(option);
				}
			});
}

function checkData() {

	var workingCompany = $("input[name='workingCompany']");
	var salary = $("input[name='salary']");
	var enterCompanyTime = $("input[name='enterCompanyTime']");

	if ($.trim(workingCompany.val()) == '' || $.trim(salary.val()) == ''
			|| isNaN($.trim(salary.val()))
			|| $.trim(enterCompanyTime.val()) == '' || $.trim(salary.val()) <= 0) {
		alert("入职时间、就职公司与年薪不能为空，并且薪水应该是有效的数字");
		return false;
	} else {
		document.JobInfo.submit();
	}

}
